package org.ahuanlien.crm.service.impl;

import org.ahuanlien.crm.domain.Task;
import org.ahuanlien.crm.mapper.TaskMapper;
import org.ahuanlien.crm.query.StaffManagementQueryObject;
import org.ahuanlien.crm.service.ITaskService;
import org.ahuanlien.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class TaskServiceImpl implements ITaskService{

    @Autowired
    TaskMapper taskMapper;

    @Override
    public void deleteByPrimaryKey(Long id) {
        taskMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(Task record) {
        if (record.getId() != null) {
            taskMapper.updateByPrimaryKey(record);
        } else {
            record.setState(false);
            taskMapper.insert(record);
        }
    }

    @Override
    public Task selectByPrimaryKey(Long id) {
        return taskMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Task> selectAll() {
        return taskMapper.selectAll();
    }
    @Override
    public PageResult query(StaffManagementQueryObject qo) {
        int count = taskMapper.query4Count(qo);
        if (count == 0) {
            return new PageResult(count, Collections.EMPTY_LIST);
        }
        List<Task> result = taskMapper.query4List(qo);
        return new PageResult(count, result);
    }

    @Override
    public void changeState(Long id) {
        taskMapper.changeState(id);
    }

}
